<template>
    <div>
     <el-form :model="formData" :rules="rules" ref="formData" label-width="100px">
      <el-form-item label="父节点名字" prop="parentName" >
        <el-input v-model="formData.parentName" placeholder="格式:   第*章"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="text" @click="handleClose">重 置</el-button>
      <el-button type="primary" @click="handleSubmit"
                 :loading="loading">{{loading?'提交中...':'确认提交'}}</el-button>
    </span> 
    </div>
</template>

<script>
  //import {getAllRoleList} from "../../../api/modules/role";
  import {add} from "@/api/modules/coursevideo";
  import {getCookie} from '@/libs/cookie'
  
  export default {
    name: "father",

    props: {
      visible: {
        type: Boolean
      },
      title: {
        type: String,
        default: '新增'
      },

      defaultFormData: {
        type: Object
      },
    },
    data() {
      return {
    
        loading: false,
        username:'',
        formData: {
          id:'',
          videoUrl:'0',
          courseId:'',
          parent:'0',
          childName:'0',
          parentName:'',
          name:''
        },
        address:[],
        rules: {
          parentName: [
            {required: true, message: "楼栋名不能为空", trigger: "blur"}
          ],
    
        },
        message:{
          msg1:'设置成功',
           msg2:'父节点不能为空'
        },
        refresh: false
      }
    },
    mounted() {

        let courseID = JSON.parse(getCookie("courseID") || '{}');
        this.formData.courseId = courseID.courseID
      //  console.log(this.formData)
    },
    methods: {
      
      handleChange(value) {
        console.log(value);
      },
       handleClose() {
 
        this.$refs.formData.resetFields()
      },
      handleSubmit() {
        this.$refs.formData.validate(valid => {
         this.formData.name = this.formData.parentName
          if (valid) {
            this.loading = true
            if(this.formData.parentName==''){
              this.toast(this.message.msg2,10)
              this.loading = false
                this.refresh = true
            } 
              add({
                ...this.formData,
              }).then(res => {
                this.loading = false
                if (res.success) {
                  this.refresh = true
                  this.toast(this.message.msg1)
                  location.reload()
                }
              })
           
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
